window.$config = {
    host : '',
    // host : '/mmp_bak/htdocs',
    url: location.href,
    getCookie :function (c_name) {
        if (document.cookie.length>0) {
            var c_start=document.cookie.indexOf(c_name + "=")
            if (c_start!=-1)
            {
                c_start=c_start + c_name.length+1
                var c_end=document.cookie.indexOf(";",c_start)
                if (c_end==-1) c_end=document.cookie.length
                return unescape(document.cookie.substring(c_start,c_end))
            }
        }
        return ""
    },
    IsPC : function () {
        var userAgentInfo = navigator.userAgent;
        var Agents = ["Android", "iPhone",
            "SymbianOS", "Windows Phone",
            "iPad", "iPod"];
        var flag = true;
        for (var v = 0; v < Agents.length; v++) {
            if (userAgentInfo.indexOf(Agents[v]) > 0) {
                flag = false;
                break;
            }
        }
        return flag;
    },
    iswx : function(){
        var ua = window.navigator.userAgent.toLowerCase();
        if(ua.match(/MicroMessenger/i) == 'micromessenger'){
            return true;
        }else{
            return false;
        }
    },
    iswx : function(){
        var ua = window.navigator.userAgent.toLowerCase();
        if(ua.match(/MicroMessenger/i) == 'micromessenger'){
            return true;
        }else{
            return false;
        }
    },
    wxConfig: function (config) {
        wx.config({
            debug: false,
            appId: config.appId,
            timestamp: config.timestamp,
            nonceStr: config.nonceStr,
            signature: config.signature,
            jsApiList: [
                'chooseImage', 'uploadImage', 'previewImage' ,'onMenuShareAppMessage', 'onMenuShareTimeline', 'onMenuShareQQ', 'onMenuShareWeibo'
            ]
        });

    },
    wxShare : function(Option) {
        var num = 0,
            _this = this,
            time = setInterval(function () {
                if(num>100) {
                    clearTimeout(time);
                }
                try {
                    if (!wx || !oe_wxconfig) {};
                } catch (e) {
                    num++;return;
                }

                clearTimeout(time);

                _this.wxConfig(oe_wxconfig);
                //初始化
                if (!Option) Option = {};
                var title = Option.title ? Option.title : "广州市老旧小区微改造规划设计方案竞赛",
                    summary = Option.cont ? Option.cont : "一小群，优质的社群营销工具",
                    link = Option.url ? Option.url : location.href,
                    thumb = Option.logo ? Option.logo : 'http://' + location.hostname + '/logo.jpg',
                    content = {
                        title: title,
                        desc: summary,
                        link: link,
                        imgUrl: thumb,
                        /*type: '',
                        dataUrl: '',*/
                        success: function () {
                        },
                        cancel: function () {
                        }
                    }
                wx.ready(function () {
                    wx.onMenuShareTimeline(content);
                    wx.onMenuShareAppMessage(content);
                    wx.onMenuShareQQ(content);
                    wx.onMenuShareWeibo(content);
                    // alert(JSON.stringify(content))
                });
            },100);
    },
    wxinit : function () {
        var localUrl = location.href,
            boole = false,
            shareArry = [
                '?from=timeline',
                '?from=groupmessage',
                '?from=singlemessage',
                '&isappinstalled=0',
                '&isappinstalled=1'
            ];
        for (var i in shareArry) {
            if (localUrl.indexOf(shareArry[i]) >= 0) {
                localUrl = localUrl.replace(shareArry[i], '');
                boole = true;
            }
        }
        if (boole) {
            location.replace(localUrl);
        }
        /*if (!this.iswx()) return;
        var hostname = 'www.yixiaoqun.com';
        var jwx1 = document.createElement('script');
        jwx1.setAttribute('src', 'http://res.wx.qq.com/open/js/jweixin-1.2.0.js');
        document.body.appendChild(jwx1);
        var jwx2 = document.createElement('script');
        jwx2.setAttribute('src', 'https://m.mp.oeeee.com/helper.php?m=WxHelper&a=config&domain=oeeee.com');
        document.body.appendChild(jwx2);*/
    }
}

$config.wxinit();